define(['jquery', 'bootstrap', 'backend', 'table', 'form',  'bootstrap-table-jumpto'], function ($, undefined, Backend, Table, Form, Jump) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'custom/niu/index' + location.search,
                    add_url: 'custom/niu/add',
                    edit_url: 'custom/niu/edit',
                    del_url: 'custom/niu/del',
                    multi_url: 'custom/niu/multi',
                    table: 'custom_niu',
                }
            });

            var table = $("#table");
            $('.my-create-file').click(function () {
                var options = table.bootstrapTable('getOptions');
                var search = options.queryParams({});

                var filter = search.filter;
                var op = search.op;
                var url =  'custom/niu/exportXlsx?filter=' + filter + '&op=' + op;
                url = Fast.api.fixurl(url);
                window.open(url);
            });
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                showExport: false,
                showJumpto: true,
                searchFormVisible: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'user.parent_id', title: '上级ID', formatter: function (value, row, index) {
                            if (value == 0) {
                                return '暂无上级';
                            } else {
                                return value;
                            }
                        }},
                        {field: 'user.nickname', title: '昵称', operate: 'like'},
                        {field: 'real_name', title: '客户姓名', operate: 'like'},
                        {field: 'name', title: __('Name'), operate: 'like'},
                        {field: 'phone', title:'电话', operate: 'like'},
                        {field: 'address', title: __('Address'), operate:false, cellStyle:Controller.api.css.address},
                        {field: 'type_data.str', title: '牛场信息', operate:false, cellStyle:Controller.api.css.str},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            css: {
                str: function () {
                    return {
                        css: {
                            'max-width': '100px',
                            'max-height': '150px'
                        }
                    };
                },
                address: function () {
                    return {
                        css: {
                            'max-width': '100px',
                            'max-height': '150px'
                        }
                    };
                }
            }
        }
    };
    return Controller;
});